﻿Imports System.Data.SqlClient

Public Class frmLiquidadores
    Dim Liquidadores As New clsLiquidadores

    Private Sub frmLiquidadores_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStrip1.Cursor = Cursors.Hand
        ToolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System

        CargaEmpleados()
        CargaLiquidadores()




    End Sub
    Sub CargaEmpleados()
        dgDisponibles.Rows.Clear()

        Dim cnConn As New SqlConnection
        Dim cmdBuscar As New SqlCommand
        Dim rdBuscar As SqlDataReader
        Dim strSql As String


        Try
            cnConn.ConnectionString = CitraConnection
            strSql = "SELECT NombreCompleto FROM Empleados WHERE EstadoEmpleado<>'B' ORDER BY NombreCompleto"
            cmdBuscar.Connection = cnConn
            cmdBuscar.CommandText = strSql

            cnConn.Open()
            rdBuscar = cmdBuscar.ExecuteReader

            Do While rdBuscar.Read()
                dgDisponibles.Rows.Add(rdBuscar("NombreCompleto"))
            Loop
        Catch ex As Exception
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try
    End Sub
    Sub CargaLiquidadores()
        dgAutorizadas.Rows.Clear()

        Dim cnConn As New SqlConnection
        Dim cmdBuscar As New SqlCommand
        Dim rdBuscar As SqlDataReader
        Dim strSql As String


        Try
            cnConn.ConnectionString = InitialConnection
            strSql = "SELECT NombreCompleto FROM Liquidadores ORDER BY NombreCompleto"
            cmdBuscar.Connection = cnConn
            cmdBuscar.CommandText = strSql

            cnConn.Open()
            rdBuscar = cmdBuscar.ExecuteReader

            Do While rdBuscar.Read()
                dgAutorizadas.Rows.Add(rdBuscar("NombreCompleto"))
            Loop
        Catch ex As Exception
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim IdEmpleado As Integer = BuscarIntDatoCitra("SELECT IdEmpleado FROM Empleados WHERE NombreCompleto='" & dgDisponibles.CurrentRow.Cells(0).Value & "'")

        Liquidadores.IdEmpleado = IdEmpleado
        Liquidadores.NombreCompleto = dgDisponibles.CurrentRow.Cells(0).Value
        Liquidadores.BaseDatos = CITRA
        Liquidadores.EstadoEmpleado = BuscarStrDatoCitra("SELECT EstadoEmpleado FROM Empleados WHERE IdEmpleado=" & IdEmpleado)
        Liquidadores.Codigo = BuscarStrDatoCitra("SELECT Codigo FROM Empleados WHERE IdEmpleado=" & IdEmpleado)
        Liquidadores.Insertar()

        CargaLiquidadores()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim IdEmpleado As Integer = BuscarDblDatoInicial("SELECT IdEmpleado FROM Liquidadores WHERE NombreCompleto='" & dgAutorizadas.CurrentRow.Cells(0).Value & "'")

        Call SetSqlInicial("DELETE FROM Liquidadores WHERE IdEmpleado=" & IdEmpleado)

        CargaLiquidadores()

    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Close()

    End Sub
End Class